
public class QueueManager {
    private final Map<String, ConcurrentLinkedQueue<QueuePlayer>> serverQueues = new ConcurrentHashMap<>();
    private final ScheduledExecutorService executor = Executors.newScheduledThreadPool(2); // 独立线程池

    public void addPlayer(String server, Player player, int priority) {
        QueuePlayer qPlayer = new QueuePlayer(player, priority);
        ConcurrentLinkedQueue<QueuePlayer> queue = serverQueues.computeIfAbsent(server, k -> new ConcurrentLinkedQueue<>());
        queue.add(qPlayer);
        player.sendActionBar("§e队列位置: §6" + queue.size());

        // 动态调整处理速率 (基于TPS)
        long interval = Bukkit.getTPS()[0] > 18 ? 1 : 2; // 秒
        executor.scheduleAtFixedRate(() -> processNext(server), 0, interval, TimeUnit.SECONDS);
    }

    private void processNext(String server) {
        QueuePlayer next = serverQueues.get(server).poll();
        if (next != null) {
            TeleportEngine.transfer(next.player, server); // 异步传送
        }
    }
}